1 | This folder provides an example implementation of how to add custom tcp header
|
---|
2 | options and custom socket options.
|
---|
3 |
|
---|
4 | It does this by implementing the (seldom used) tcp md5 signature.
|
---|
5 |
|
---|
6 | To enable it, add an LWIP_HOOK_FILENAME hook file, include tcp_md5.h in it and
|
---|
7 | define these hooks:
|
---|
8 |
|
---|
9 | #define LWIP_HOOK_TCP_INPACKET_PCB(pcb, hdr, optlen, opt1len, opt2, p) tcp_md5_check_inpacket(pcb, hdr, optlen, opt1len, opt2, p)
|
---|
10 | #define LWIP_HOOK_TCP_OPT_LENGTH_SEGMENT(pcb, internal_len) tcp_md5_get_additional_option_length(pcb, internal_len)
|
---|
11 | #define LWIP_HOOK_TCP_ADD_TX_OPTIONS(p, hdr, pcb, opts) tcp_md5_add_tx_options(p, hdr, pcb, opts)
|
---|
12 | #define LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err) tcp_md5_setsockopt_hook(sock, level, optname, optval, optlen, err)
|
---|
13 |
|
---|
14 | Then, in your sockets application, enable md5 signature on a socket like this:
|
---|
15 |
|
---|
16 | struct tcp_md5sig md5;
|
---|
17 | struct sockaddr_storage addr_remote; /* Initialize this to remote address and port */
|
---|
18 | memcpy(&md5.tcpm_addr, &addr_remote, sizeof(addr_remote));
|
---|
19 | strcpy(md5.tcpm_key, key); /* this is the md5 key per connection */
|
---|
20 | md5.tcpm_keylen = strlen(key);
|
---|
21 | if ((ret = setsockopt(sockfd, IPPROTO_TCP, TCP_MD5SIG, &md5, sizeof(md5))) < 0) {
|
---|
22 | perror("setsockopt TCP_MD5SIG");
|
---|
23 | return;
|
---|
24 | }
|
---|
25 |
|
---|
26 | After that, your connection (client) or all incoming connections (server) require
|
---|
27 | tcp md5 signatures.
|
---|