lsock.c (24583) | lsock.c (31183) |
---|---|
1/* | 1/* |
2 * lsock.c (C) 1995 Darren Reed | 2 * lsock.c (C) 1995-1997 Darren Reed |
3 * | 3 * |
4 * The author provides this program as-is, with no gaurantee for its 5 * suitability for any specific purpose. The author takes no responsibility 6 * for the misuse/abuse of this program and provides it for the sole purpose 7 * of testing packet filter policies. This file maybe distributed freely 8 * providing it is not modified and that this notice remains in tact. | 4 * Redistribution and use in source and binary forms are permitted 5 * provided that this notice is preserved and due credit is given 6 * to the original author and the contributors. |
9 */ | 7 */ |
10#if !defined(lint) && defined(LIBC_SCCS) 11static char sccsid[] = "@(#)lsock.c 1.2 1/11/96 (C)1995 Darren Reed"; | 8#if !defined(lint) 9static const char sccsid[] = "@(#)lsock.c 1.2 1/11/96 (C)1995 Darren Reed"; 10static const char rcsid[] = "@(#)$Id: lsock.c,v 2.0.2.7 1997/09/28 07:13:32 darrenr Exp $"; |
12#endif 13#include <stdio.h> 14#include <unistd.h> 15#include <string.h> 16#include <stdlib.h> 17#include <stddef.h> 18#include <pwd.h> 19#include <sys/types.h> --- 20 unchanged lines hidden (view full) --- 40#include <linux/netdevice.h> 41#include <nlist.h> 42#include <sys/user.h> 43#include <sys/socket.h> 44#include <math.h> 45#include <netinet/in.h> 46#include <netinet/in_systm.h> 47#include <net/if.h> | 11#endif 12#include <stdio.h> 13#include <unistd.h> 14#include <string.h> 15#include <stdlib.h> 16#include <stddef.h> 17#include <pwd.h> 18#include <sys/types.h> --- 20 unchanged lines hidden (view full) --- 39#include <linux/netdevice.h> 40#include <nlist.h> 41#include <sys/user.h> 42#include <sys/socket.h> 43#include <math.h> 44#include <netinet/in.h> 45#include <netinet/in_systm.h> 46#include <net/if.h> |
48#if LINUX < 0103 | 47#if LINUX < 0200 |
49#include <net/inet/sock.h> 50#endif 51#include "ipsend.h" 52 53int nproc; 54struct task_struct *proc; 55 56#ifndef KMEM --- 126 unchanged lines hidden (view full) --- 183 { 184 fprintf(stderr, "read(%#x,%#x,%d) - f_inode - failed\n", 185 f->f_inode, i, sizeof(*i)); 186 return NULL; 187 } 188 return i->u.socket_i.data; 189} 190 | 48#include <net/inet/sock.h> 49#endif 50#include "ipsend.h" 51 52int nproc; 53struct task_struct *proc; 54 55#ifndef KMEM --- 126 unchanged lines hidden (view full) --- 182 { 183 fprintf(stderr, "read(%#x,%#x,%d) - f_inode - failed\n", 184 f->f_inode, i, sizeof(*i)); 185 return NULL; 186 } 187 return i->u.socket_i.data; 188} 189 |
191int do_socket(dev, mtu, ti, gwip, flags) | 190int do_socket(dev, mtu, ti, gwip) |
192char *dev; 193int mtu; 194struct tcpiphdr *ti; 195struct in_addr gwip; | 191char *dev; 192int mtu; 193struct tcpiphdr *ti; 194struct in_addr gwip; |
196int flags; | |
197{ 198 struct sockaddr_in rsin, lsin; 199 struct sock *s, sk; 200 int fd, nfd, len; 201 202 printf("Dest. Port: %d\n", ti->ti_dport); 203 204 fd = socket(AF_INET, SOCK_STREAM, 0); --- 17 unchanged lines hidden (view full) --- 222 { 223 perror("bind"); 224 return -1; 225 } 226 len = sizeof(lsin); 227 (void) getsockname(fd, (struct sockaddr *)&lsin, &len); 228 ti->ti_sport = lsin.sin_port; 229 printf("sport %d\n", ntohs(lsin.sin_port)); | 195{ 196 struct sockaddr_in rsin, lsin; 197 struct sock *s, sk; 198 int fd, nfd, len; 199 200 printf("Dest. Port: %d\n", ti->ti_dport); 201 202 fd = socket(AF_INET, SOCK_STREAM, 0); --- 17 unchanged lines hidden (view full) --- 220 { 221 perror("bind"); 222 return -1; 223 } 224 len = sizeof(lsin); 225 (void) getsockname(fd, (struct sockaddr *)&lsin, &len); 226 ti->ti_sport = lsin.sin_port; 227 printf("sport %d\n", ntohs(lsin.sin_port)); |
230 nfd = initdevice(dev, ntohs(lsin.sin_port)); | 228 nfd = initdevice(dev, ntohs(lsin.sin_port), 0); |
231 232 if (!(s = find_tcp(fd, ti))) 233 return -1; 234 235 bzero((char *)&rsin, sizeof(rsin)); 236 rsin.sin_family = AF_INET; 237 bcopy((char *)&ti->ti_dst, (char *)&rsin.sin_addr, 238 sizeof(struct in_addr)); 239 rsin.sin_port = ti->ti_dport; 240 if (connect(fd, (struct sockaddr *)&rsin, sizeof(rsin)) == -1 && 241 errno != EINPROGRESS) 242 { 243 perror("connect"); 244 return -1; 245 } 246 KMCPY(&sk, s, sizeof(sk)); 247 ti->ti_win = sk.window; 248 ti->ti_seq = sk.sent_seq - 1; 249 ti->ti_ack = sk.rcv_ack_seq; | 229 230 if (!(s = find_tcp(fd, ti))) 231 return -1; 232 233 bzero((char *)&rsin, sizeof(rsin)); 234 rsin.sin_family = AF_INET; 235 bcopy((char *)&ti->ti_dst, (char *)&rsin.sin_addr, 236 sizeof(struct in_addr)); 237 rsin.sin_port = ti->ti_dport; 238 if (connect(fd, (struct sockaddr *)&rsin, sizeof(rsin)) == -1 && 239 errno != EINPROGRESS) 240 { 241 perror("connect"); 242 return -1; 243 } 244 KMCPY(&sk, s, sizeof(sk)); 245 ti->ti_win = sk.window; 246 ti->ti_seq = sk.sent_seq - 1; 247 ti->ti_ack = sk.rcv_ack_seq; |
248 ti->ti_flags = TH_SYN; |
|
250 | 249 |
251 if (send_tcp(nfd, mtu, ti, gwip, TH_SYN) == -1) | 250 if (send_tcp(nfd, mtu, (ip_t *)ti, gwip) == -1) |
252 return -1; 253 (void)write(fd, "Hello World\n", 12); 254 sleep(2); 255 close(fd); 256 return 0; 257} | 251 return -1; 252 (void)write(fd, "Hello World\n", 12); 253 sleep(2); 254 close(fd); 255 return 0; 256} |