aboutsummaryrefslogtreecommitdiff
path: root/talker.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-23 17:30:45 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-23 17:30:45 -0400
commit3b2aa8c271bf5cd5497decb6577afe5fd7339f57 (patch)
treebc1d39ad76b15f58ddf61385645fa87a59fb1157 /talker.c
parentb417bcc57b9fd49f360087c32c97293a6bc7d2be (diff)
parent1e9ac5407ef4f2cddc745f35f33a860446526cea (diff)
merge post-warmup with main
Diffstat (limited to 'talker.c')
-rw-r--r--talker.c67
1 files changed, 0 insertions, 67 deletions
diff --git a/talker.c b/talker.c
deleted file mode 100644
index bb801e5..0000000
--- a/talker.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
-** talker.c -- a datagram "client" demo
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-
-#define SERVERPORT "4950" // the port users will be connecting to
-
-int main(int argc, char *argv[])
-{
- int sockfd;
- struct addrinfo hints, *servinfo, *p;
- int rv;
- int numbytes;
-
- if (argc != 3) {
- fprintf(stderr,"usage: talker hostname message\n");
- exit(1);
- }
-
- memset(&hints, 0, sizeof hints);
- hints.ai_family = AF_INET6; // set to AF_INET to use IPv4
- hints.ai_socktype = SOCK_DGRAM;
-
- if ((rv = getaddrinfo(argv[1], SERVERPORT, &hints, &servinfo)) != 0) {
- fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
- return 1;
- }
-
- // loop through all the results and make a socket
- for(p = servinfo; p != NULL; p = p->ai_next) {
- if ((sockfd = socket(p->ai_family, p->ai_socktype,
- p->ai_protocol)) == -1) {
- perror("talker: socket");
- continue;
- }
-
- break;
- }
-
- if (p == NULL) {
- fprintf(stderr, "talker: failed to create socket\n");
- return 2;
- }
-
- if ((numbytes = sendto(sockfd, argv[2], strlen(argv[2]), 0,
- p->ai_addr, p->ai_addrlen)) == -1) {
- perror("talker: sendto");
- exit(1);
- }
-
- freeaddrinfo(servinfo);
-
- printf("talker: sent %d bytes to %s\n", numbytes, argv[1]);
- close(sockfd);
-
- return 0;
-} \ No newline at end of file