Commit 2c4701fa authored by Joanne Hugé's avatar Joanne Hugé

Make the server ip a parameter

parent 64b3fb41
ARM_CC = arm-linux-gnueabihf-gcc
ARM_PROG = main_arm
PROG = main
SRCDIR = ../src
......@@ -15,6 +17,14 @@ CFLAGS += -std=gnu99
vpath %.c $(SRCDIR)
$(ARM_PROG): FORCE
make clean
$(eval CC:=arm-linux-gnueabihf-gcc)
make $(PROG)
mv $(PROG) $(ARM_PROG)
FORCE:
$(PROG): $(OBJS)
$(CC) $(LDFLAGS) $^ -o $@
......@@ -26,4 +36,4 @@ run: $(PROG)
clean:
$(RM) $(OBJS) $(PROG) $(subst .c,.d,$(SRCS))
.PHONY: clean
.PHONY: clean FORCE
......@@ -3,10 +3,15 @@
#include "getip.h"
#include "send_packet.h"
int main() {
int main(int argc, char * argv[]) {
if( argc != 2) {
printf("Usage: %s server_ip\n", argv[0]);
return -1;
}
for(int i = 0; i < 100; i++)
send_udp_packet();
send_udp_packet(argv[1]);
return 0;
}
#include "send_packet.h"
/*
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
......@@ -20,10 +12,9 @@
#include <arpa/inet.h>
#define SERVER_IP "192.168.0.100"
#define SERVER_PORT "50000"
int send_udp_packet(void) {
int send_udp_packet(const char * server_ip) {
int status;
int sockfd;
......@@ -37,7 +28,7 @@ int send_udp_packet(void) {
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
status = getaddrinfo(SERVER_IP, SERVER_PORT, &hints, &servinfo);
status = getaddrinfo(server_ip, SERVER_PORT, &hints, &servinfo);
if( status != 0 ) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
printf("getaddrinfo error, exiting...\n");
......@@ -66,7 +57,7 @@ int send_udp_packet(void) {
freeaddrinfo(servinfo);
printf("Sent %d bytes to %s\n", bytes_sent, SERVER_IP);
printf("Sent %d bytes to %s\n", bytes_sent, server_ip);
close(sockfd);
return 0;
}
#ifndef SEND_PACKET_H
#define SEND_PACKET_H
int send_udp_packet(void);
int send_udp_packet(const char * ip4);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment