source: abuse/tags/pd/abuse/net/netdrv.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 12 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <fcntl.h>
4#include <unistd.h>
5#include <sys/ioctl.h>
6#include <sys/stat.h>
7#include <sys/types.h>
8#include <sys/time.h>
9#include <string.h>
10#include <signal.h>
11#include <netinet/in.h>
12#include <sys/socket.h>
13
14#include <netdb.h>
15#include "nstruct.hpp"
16
17
18
19int setup_udp_port(int port)      // returns fd or -1
20{
21  int fd=socket(AF_INET,SOCK_DGRAM,0);
22  sockaddr_in host;
23  memset( (char*) &host,0, sizeof(host));
24  host.sin_family = AF_INET;
25  host.sin_port = htons(port);
26  host.sin_addr.s_addr = htonl (INADDR_ANY);
27  if (bind(fd, (struct sockaddr *) &host, sizeof(sockaddr_in))==-1)
28    return -1;
29  else if (listen(fd,1)==-1)
30    return -1;
31  return fd;
32}
33
34int udp_connect(char *rhost, int port)
35{
36  int fd=socket(AF_INET,SOCK_DGRAM,0);
37  hostent *hp=gethostbyname(rhost);
38  if (!rhost)
39    return -1;
40
41  sockaddr_in host;
42  memset( (char*) &host,0, sizeof(host));
43  host.sin_family = AF_INET;
44  host.sin_port = htons(port);
45  host.sin_addr.s_addr = htonl (INADDR_ANY);
46  memcpy(&host.sin_addr,hp->h_addr,hp->h_length);
47   
48  if (connect(fd, (struct sockaddr *) &host, sizeof(host))==-1)
49    return -1;
50
51  return fd;
52}
53
54
55
56int catch_sigs[]={SIGHUP,SIGINT,SIGQUIT,SIGILL,SIGABRT,
57                  SIGIOT,SIGFPE,SIGKILL,SIGUSR1,SIGSEGV,
58                  SIGUSR2,SIGPIPE,SIGTERM,SIGSTKFLT,SIGCHLD,
59                  SIGCONT,SIGSTOP,SIGTSTP,SIGTTIN,SIGTTOU,-1};
60
61
62
63int net_init(int argc, char **argv)
64{
65  for (int i=1;i<argv;i++)
66    if (!strcmp(argv[i],"-port"))
67    {
68    }
69  }
70
71}
72
73
74main(int argc, char **argv)
75{
76  int fail=0;
77  if (argc<2)
78    fail=1;
79  else
80  {
81    int shmid;
82    if (sscanf(argv[1],"%d")!=1)
83      fail=1;
84    else
85    {
86     
87    }
88  }
89
90  { fprintf(stderr,
91            "Abuse UNIX network driver is automatically run by abuse\n"
92            "it cannot be run stand-alone\n");
93    exit(0);
94  }
95
96
97}
98
99
100
Note: See TracBrowser for help on using the repository browser.