forked from AllenDowney/ExercisesInC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d455fd
commit 8ea9ceb
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <sys/types.h> | ||
#include <sys/socket.h> | ||
#include <sys/time.h> | ||
#include <time.h> | ||
#include <netinet/in.h> | ||
#include <netinet/in_systm.h> | ||
#include <netinet/ip.h> | ||
#include <netinet/ip_icmp.h> | ||
#include <netinet/udp.h> | ||
#include <arpa/inet.h> | ||
#include <netdb.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <getopt.h> | ||
#include <sys/un.h> | ||
#include <stdarg.h> | ||
#include <syslog.h> | ||
#include <unistd.h> | ||
|
||
#define BUFSIZE 1500 | ||
|
||
typedef struct rec { /* outgoing UDP data */ | ||
u_short seq; /* sequence number */ | ||
} Rec; | ||
|
||
typedef struct timeval Timeval; | ||
typedef struct sockaddr Sockaddr; | ||
|
||
#define max(a,b) ((a) > (b) ? (a) : (b)) | ||
|
||
/* the following are prototypes for the Stevens utilities in util.c */ | ||
|
||
void Sendto(int fd, const void *ptr, size_t nbytes, int flags, | ||
const struct sockaddr *sa, socklen_t salen); | ||
|
||
Sockaddr *sasend; /* socket addresses for various purposes */ | ||
Sockaddr *sarecv; | ||
Sockaddr *salast; | ||
Sockaddr *sabind; | ||
|
||
socklen_t salen; /* length of a socket address */ | ||
|
||
/* other global variables */ | ||
|
||
int seq; | ||
|
||
char recvbuf[BUFSIZE]; | ||
char sendbuf[BUFSIZE]; | ||
|
||
int sendfd, recvfd; | ||
int pipefd[2]; /* the pipe for the alarm handler */ | ||
|
||
// Sockaddr *sasend; /* socket addresses for various purposes */ | ||
// Sockaddr *sarecv; | ||
// Sockaddr *salast; | ||
// Sockaddr *sabind; | ||
|
||
// socklen_t salen; /* length of a socket address */ | ||
int datalen; /* length of the data in a datagram */ | ||
int max_ttl; | ||
|
||
u_short sport; /* source UDP port # */ | ||
|
||
/* 668 = the neighbor of the beast */ | ||
Timeval sendtv[1]; | ||
Timeval recvtv[1]; | ||
Timeval difftv[1]; | ||
|
||
void err_sys (char *fmt, ...); | ||
void err_quit (char *fmt, ...); | ||
char *Sock_ntop_host(const struct sockaddr *sa, socklen_t salen); | ||
int sock_cmp_addr(const struct sockaddr *sa1, | ||
const struct sockaddr *sa2, socklen_t salen); | ||
void sock_set_port(struct sockaddr *sa, socklen_t salen, int port); | ||
void tv_sub (struct timeval *out, struct timeval *in); | ||
char *icmpcode_v4(int code); | ||
void *Calloc(size_t n, size_t size); | ||
void Gettimeofday(struct timeval *tv, void *foo); | ||
void Pipe(int *fds); | ||
void Bind(int fd, const struct sockaddr *sa, socklen_t salen); | ||
void Setsockopt(int fd, int level, int optname, const void *optval, | ||
socklen_t optlen); | ||
struct addrinfo *Host_serv(const char *host, const char *serv, | ||
int family, int socktype); | ||
ssize_t Read(int fd, void *ptr, size_t nbytes); | ||
void Write(int fd, void *ptr, size_t nbytes); | ||
ssize_t Recvfrom(int fd, void *ptr, size_t nbytes, int flags, | ||
struct sockaddr *sa, socklen_t *salenptr); | ||
|
||
typedef void Sigfunc(int); | ||
Sigfunc *Signal(int signo, Sigfunc *func); | ||
|
||
void loop_ttl (); |