106 lines
2.0 KiB
C
106 lines
2.0 KiB
C
/*
|
|
===============================================================================
|
|
|
|
Net
|
|
|
|
===============================================================================
|
|
*/
|
|
#ifndef NET_H
|
|
#define NET_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#if defined (WIN32)
|
|
#include <Windows.h>
|
|
#include <Ws2tcpip.h>
|
|
#include <Winsock2.h>
|
|
#else
|
|
#include <sys/socket.h>
|
|
#include <arpa/inet.h>
|
|
#include <netinet/in.h>
|
|
#if defined (sun)
|
|
/* For Solaris 2.6, as it lacks SIOCGIFCONF */
|
|
#include <sys/sockio.h>
|
|
#endif
|
|
#endif
|
|
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h> //
|
|
#include <net/if.h> // for ifreq
|
|
|
|
#include "common.h" // for config
|
|
#include "con/console.h"
|
|
|
|
#include <inttypes.h>
|
|
#include <stdint.h>
|
|
|
|
#define MESSAGE_OPEN 0
|
|
|
|
struct in_addr local_interface;
|
|
struct sockaddr_in group_socket;
|
|
struct ip_mreq group;
|
|
int listen_socket;
|
|
int send_socket;
|
|
|
|
/* "bools" */
|
|
int is_listening;
|
|
int is_sending;
|
|
int is_group_socket_set;
|
|
|
|
/* ifreq */
|
|
struct ifconf ifconf;
|
|
struct ifreq ifreq[31];
|
|
int interfaces;
|
|
char *ip_list[16];
|
|
char *dev_list[16];
|
|
|
|
/* listen */
|
|
struct timeval listen_tv;
|
|
fd_set master_fds;
|
|
fd_set read_fds;
|
|
int max_fd;
|
|
int i;
|
|
|
|
char data_buffer[512];
|
|
int data_buffer_length;
|
|
|
|
char ip_address[15];
|
|
char port[15];
|
|
|
|
int setIp(const char string[]);
|
|
|
|
int initNetwork();
|
|
|
|
void getInterfaces(); // same v
|
|
void freeInterfaces(); // change to int
|
|
|
|
void startSockets(const char *value);
|
|
void stopSockets(const char *value);
|
|
void restartSockets(const char *value);
|
|
|
|
int startSendSocket();
|
|
int stopSendSocket();
|
|
int openSendSocket();
|
|
int closeSendSocket();
|
|
int startListenSocket();
|
|
int stopListenSocket();
|
|
int openListenSocket();
|
|
int closeListenSocket();
|
|
int receiveSocket(int send_socket);
|
|
int checkSocket();
|
|
int sendMulticast(int send_socket, struct sockaddr_in *group_socket, char data_buffer[], int data_length);
|
|
void sendOpen();
|
|
|
|
void receiveOpen(const char packet[], size_t packet_size);
|
|
int handleOpenMessage(const char packet[]);
|
|
|
|
int setString(char *destination, const char source[]);
|
|
char *stripString(const char string[]);
|
|
|
|
#endif
|