Select Git revision
Fuzzer.java
Forked from
Toby Murray / swen90006-a2-2019
Source project has a limited visibility.
mysever.c 4.67 KiB
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <ctype.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <string.h>
#include <strings.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define MAXFD 2
int main(int argc, char ** argv)
{
int sockfd, newsockfd, portno; // clilen;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
socklen_t clilen;
int n;
char * c;//
if (argc < 3)
{
fprintf(stderr, "usage: %s ip port\n", argv[0]);
return 0;
}
/* Create TCP socket */
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
perror("ERROR opening socket");
exit(EXIT_FAILURE);
}
// reuse the socket if possible
int const reuse = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int)) < 0)
{
perror("setsockopt");
exit(EXIT_FAILURE);
}
portno = atoi(argv[2]);
/* Create address we're going to listen on (given port number)
- converted to network byte order & any IP address for this machine */
bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;//differ
serv_addr.sin_port = htons(portno); // store in machine-neutral format
/* Bind address to the socket */
if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
perror("ERROR on binding");
exit(EXIT_FAILURE);
}
/* Listen on socket - means we're ready to accept connections -
incoming connection requests will be queued */
listen(sockfd, 5);