EGong

git clone git://xatko.vsos.ethz.ch/EGong.git
Log | Files | Refs

CNC.c (1268B)


      1 #define WIN32_LEAN_AND_MEAN
      2 #include <EGong/CNC.h>
      3 #include <EGong/Packet.h>
      4 #include <EGong/Util/Socket.h>
      5 #include <EGong/Util/Log.h>
      6 #include <EGong/Util/Waiter.h>
      7 #include <string.h>
      8 #include <unistd.h>
      9 #ifdef USE_GTK
     10 	#include <EGong/Interfaces/GTK.h>
     11 #endif
     12 
     13 
     14 int EGong_cnc_sendmessage_broad(const String *msg){
     15 	return EGong_cnc_sendmessage(msg, NULL);
     16 }
     17 int EGong_cnc_sendmessage(const String *msg, const char *dest){
     18 	if(dest==NULL){
     19 		dest="255.255.255.255";
     20 	}
     21 	struct EGong_packet packet;
     22 	EGong_generate_packet(&packet, msg);
     23 	if(EGong_send_packet(&packet, dest)<0){
     24 		do_log("Couldn't send packet.", LOG_TYPE_NORMAL, LOG_LEVEL_WARNING);
     25 	}
     26 	else{
     27 		do_log("Message sent", LOG_TYPE_NORMAL, LOG_LEVEL_DEBUG);
     28 	}
     29 	return 0;
     30 }
     31 
     32 int EGong_cnc_getmessage(String *msg){
     33 	struct EGong_packet packet;
     34 	int ret=EGong_get_packet(NULL, &packet);
     35 	if(ret!=0){
     36 		return ret;
     37 	}
     38 	if(EGong_packet_verify(&packet, NULL)){
     39 		msg->data=packet.message.data;
     40 		msg->length=packet.message.length;
     41 	}
     42 	else{
     43 		EGong_packet_free(&packet);
     44 		do_log("Packet didn't verify.", LOG_TYPE_NORMAL, LOG_LEVEL_INFO);
     45 		return -2;
     46 	}
     47 	return ret;
     48 }
     49 void EGong_cnc_freemessage(String *msg){
     50 	struct EGong_packet virtpack;
     51 	virtpack.message.data=msg->data;
     52 	EGong_packet_free(&virtpack);
     53 }
     54