2 test-example/bogus-setup-request 127.0.0.1 19098 test-example/inside/inside 127.0.0.1 16096 test-example/outside/outside
6 #include <sys/socket.h>
7 #include <netinet/in.h>
17 | 00000 00 00 00 00 00 00 00 01 01 01 01 01 00 1a 74 65 ........ ......te |
18 ~~~~~~~~~~~ ~~~~~~~~~~~ ~~~~~~~~~~~ ~~~~~|~~~~~
19 sessionid sender's type sender's
20 zero in index fixed for name
23 | 00010 73 74 2d 65 78 61 6d 70 6c 65 2f 69 6e 73 69 64 st-examp le/insid |
24 | 00020 65 2f 69 6e 73 69 64 65 00 1c 74 65 73 74 2d 65 e/inside ..test-e |
25 ~~~~~|~~~~~~~~~~~~~~~~~
28 | 00030 78 61 6d 70 6c 65 2f 6f 75 74 73 69 64 65 2f 6f xample/o utside/o |
29 | 00040 75 74 73 69 64 65 8d f0 3f 35 d6 c8 1f c0 utside.. ?5.... |
30 ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
38 struct sockaddr_in sin
;
42 static void endaddr(Ep
*ep
, char **argv
, int base
) {
44 ep
->sin
.sin_family
=AF_INET
;
45 r
=inet_aton(argv
[base
],&ep
->sin
.sin_addr
); assert(r
);
46 ep
->sin
.sin_port
=htons(atoi(argv
[base
+1]));
47 ep
->name
=argv
[base
+2];
50 static void endname(uint8_t **msgp
, const Ep
*ep
) {
51 int l
=strlen(ep
->name
); assert(l
<=65535);
54 memcpy(*msgp
, ep
->name
, l
);
60 int main(int argc
, char **argv
) {
66 endaddr(&them
,argv
,4);
68 static const uint8_t mprefix
[]={
69 0x00, 0x00, 0x00, 0x00,
70 0x00, 0x00, 0x00, 0x01,
71 0x01, 0x01, 0x01, 0x01,
73 static const uint8_t msuffix
[]={
74 /* our nonce, fixed he he */
75 0x8d, 0xf0, 0x3f, 0x35, 0xd6, 0xc8, 0x1f, 0xc0
77 int msglen
= (sizeof(mprefix
) +
84 #define PREFIXSUFFIX(prefixsuffix) do { \
85 memcpy(msgp,prefixsuffix,sizeof(prefixsuffix)); \
86 msgp += sizeof(prefixsuffix); \
89 PREFIXSUFFIX(mprefix
);
94 PREFIXSUFFIX(msuffix
);
96 assert(msgp
== msg
+msglen
);
98 struct protoent
*proto
=getprotobyname("udp");
99 int fd
=socket(AF_INET
, SOCK_DGRAM
, proto
->p_proto
);
100 r
=bind(fd
,&us
.sa
,sizeof(us
.sin
)); if (r
) { perror("bind us2"); exit(1); }
103 r
=sendto(fd
,msg
,msglen
,0,&them
.sa
,sizeof(them
.sin
));
104 if (r
< 0) perror("sendto");
108 if (ferror(stdin
)) { perror("getchar"); exit(1); }