void loop(){

    if (ch_num >= 24 && ch_num <= 61) { 
        SubGHz.begin(ch_num, 0xABCD,  SUBGHZ_100KBPS, SUBGHZ_PWR_20MW);
    }
//  SubGHz.rxEnable(NULL);

    // 2015.07.29 Eiichi Saito CCA中シンクさせない
    reg_data = 0x00;
    ml7396_regwrite(REG_ADR_DEMSET3, &reg_data, 1);
    ml7396_regwrite(REG_ADR_DEMSET14, &reg_data, 1);

    reg_data = 0x30; // CCA無限実行
    ml7396_regwrite(REG_ADR_CCA_CNTRL, &reg_data, 1);

    reg_data = 0x06;
    ml7396_regwrite(REG_ADR_RF_STATUS, &reg_data, 1);

//  lcd.clear();
    lcd.home();
    lcd.print("100k");
    lcd.print(" ");
//  lcd.print("50k");
//  lcd.print("  ");

    get_sw_val();
    create_msg(ch_num, DEC, 2);
    lcd.print("c");

    lcd.setCursor(0, 1);
    get_rssi();

    create_msg(occupancy_rate, DEC, 3);
    lcd.print("%");
    lcd.print(" ");

    create_msg(max_rssi, HEX, 2);
    lcd.print(" ");

    reg_data = 0x40; // CCA無限実行
    ml7396_regwrite(REG_ADR_CCA_CNTRL, &reg_data, 1);

    reg_data = 0x08;
    ml7396_regwrite(REG_ADR_RF_STATUS, &reg_data, 1);

    // 2015.07.29 Eiichi Saito CCA中シンクさせない
    reg_data = 0x64;
    ml7396_regwrite(REG_ADR_DEMSET3, &reg_data, 1);
    reg_data = 0x27;
    ml7396_regwrite(REG_ADR_DEMSET14, &reg_data, 1);

	SubGHz.close();
	delay(500);
}
示例#2
0
static void ICACHE_FLASH_ATTR send_offer(struct dhcps_msg *m)
{
        uint8_t *end;
	    struct pbuf *p, *q;
	    u8_t *data;
	    u16_t cnt=0;
	    u16_t i;
        create_msg(m);

        end = add_msg_type(&m->options[4], DHCPOFFER);
        end = add_offer_options(end);
        end = add_end(end);

	    p = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcps_msg), PBUF_RAM);
#if DHCPS_DEBUG
		os_printf("udhcp: send_offer>>p->ref = %d\n", p->ref);
#endif
	    if(p != NULL){

#if DHCPS_DEBUG
	        os_printf("dhcps: send_offer>>pbuf_alloc succeed\n");
	        os_printf("dhcps: send_offer>>p->tot_len = %d\n", p->tot_len);
	        os_printf("dhcps: send_offer>>p->len = %d\n", p->len);
#endif
	        q = p;
	        while(q != NULL){
	            data = (u8_t *)q->payload;
	            for(i=0; i<q->len; i++)
	            {
	                data[i] = ((u8_t *) m)[cnt++];
#if DHCPS_DEBUG
					os_printf("%02x ",data[i]);
					if((i+1)%16 == 0){
						os_printf("\n");
					}
#endif
	            }

	            q = q->next;
	        }
	    }else{

#if DHCPS_DEBUG
	        os_printf("dhcps: send_offer>>pbuf_alloc failed\n");
#endif
	        return;
	    }
#if DHCPS_DEBUG
        err_t SendOffer_err_t = udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
        os_printf("dhcps: send_offer>>udp_sendto result %x\n",SendOffer_err_t);
#else
        udp_sendto( pcb_dhcps, p, &broadcast_dhcps, DHCPS_CLIENT_PORT );
#endif
	    if(p->ref != 0){
#if DHCPS_DEBUG
	        os_printf("udhcp: send_offer>>free pbuf\n");
#endif
	        pbuf_free(p);
	    }
}
示例#3
0
void
hpcrun_write_msg_to_log(bool echo_stderr, bool add_thread_id,
			const char *tag,
			const char *fmt, va_list_box* box)
{
  char buf[MSG_BUF_SIZE];

  if ((hpcrun_get_disabled() && (! echo_stderr))
      || (! hpcrun_sample_prob_active())) {
    return;
  }

  create_msg(&buf[0], sizeof(buf), add_thread_id, tag, fmt, box);
  va_list_boxp_end(box);

  if (echo_stderr){
    write(2, buf, strlen(buf));
  }

  if (check_limit && (msgs_out > msg_limit)) return;

  if (hpcrun_get_disabled()) return;

  spinlock_lock(&pmsg_lock);

  // use write to logfile file descriptor, instead of fprintf stuff
  //
  write(messages_logfile_fd(), buf, strlen(buf));
  msgs_out++;

  spinlock_unlock(&pmsg_lock);
}
示例#4
0
文件: csmsg.c 项目: rcrowder/Burt
/**
 * Helper method to build a debug msg.
 * txt is the string used to build the debug msg
 */
ScripterMsg* build_debug_msg( char* txt ) {
	ScripterMsg* msg = create_msg(DEBUG_MSG_ID);
	msg->param_count = 1;
	MsgParam* param = create_msg_param(s_to_u(txt), strlen(txt));
	msg->parameters = param;
	return msg;
}
示例#5
0
static void test_messages(void)
{
	struct mgcp_config *cfg;
	int i;

	cfg = mgcp_config_alloc();

	cfg->trunk.number_endpoints = 64;
	mgcp_endpoints_allocate(&cfg->trunk);

	mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));

	for (i = 0; i < ARRAY_SIZE(tests); i++) {
		const struct mgcp_test *t = &tests[i];
		struct msgb *inp;
		struct msgb *msg;

		printf("Testing %s\n", t->name);

		inp = create_msg(t->req);
		msg = mgcp_handle_message(cfg, inp);
		msgb_free(inp);
		if (!t->exp_resp) {
			if (msg)
				printf("%s failed '%s'\n", t->name, (char *) msg->data);
		} else if (strcmp((char *) msg->data, t->exp_resp) != 0)
			printf("%s failed '%s'\n", t->name, (char *) msg->data);
		msgb_free(msg);
	}

	talloc_free(cfg);
}
示例#6
0
int
server_msg_init(struct server_msg *msg, il_octet_string_t *event)
{
	il_http_message_t *hmsg = (il_http_message_t *)event;

	assert(msg != NULL);
	assert(event != NULL);

	memset(msg, 0, sizeof(*msg));


	msg->job_id_s = hmsg->host;
	if(msg->job_id_s == NULL) {
		set_error(IL_LBAPI, EDG_WLL_ERROR_PARSE_BROKEN_ULM, "server_msg_init: error getting id");
		return -1;
	}
	msg->len = create_msg(hmsg, &msg->msg, &msg->receipt_to, &msg->expires);
	if(msg->len < 0)
		return -1;
	/* set this to indicate new data owner */
	hmsg->data = NULL;
	hmsg->host = NULL;
	msg->ev_len = hmsg->len + 1; /* must add separator size too */
	return 0;

}
void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu)
{
	uint32_t tlli = 0xadf11820;
	const uint8_t qos_profile[] = { 0x0, 0x0, 0x04 };

	next_wanted_nu = 0;
	struct msgb *msg = create_msg(gprs_attach_llc, ARRAY_SIZE(gprs_attach_llc));
	bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, msg);
}
示例#8
0
static int std_rcv_padt(struct session* ses,
                        struct pppoe_packet *p_in,
                        struct pppoe_packet **p_out){
    ses->state = PADO_CODE;

    create_msg(BCM_PPPOE_CLIENT_STATE_PADO);
    syslog(LOG_CRIT,"PPP session terminated.\n");

    return 0;
}
示例#9
0
文件: msg.c 项目: bdidemus/wine
/**************************************************************************
 *          WsCreateMessage		[webservices.@]
 */
HRESULT WINAPI WsCreateMessage( WS_ENVELOPE_VERSION env_version, WS_ADDRESSING_VERSION addr_version,
                                const WS_MESSAGE_PROPERTY *properties, ULONG count, WS_MESSAGE **handle,
                                WS_ERROR *error )
{
    TRACE( "%u %u %p %u %p %p\n", env_version, addr_version, properties, count, handle, error );
    if (error) FIXME( "ignoring error parameter\n" );

    if (!handle || !env_version || !addr_version) return E_INVALIDARG;
    return create_msg( env_version, addr_version, properties, count, handle );
}
示例#10
0
static int std_rcv_pado(struct session* ses,
                        struct pppoe_packet *p_in,
                        struct pppoe_packet **p_out){
    
    if( verify_packet(ses, p_in) < 0)
        return -1;
    
    if(ses->state != PADO_CODE ){
        poe_error(ses,"Unexpected packet: %P",p_in);
        return 0;
    }
    
    
    if (DEB_DISC2) {
        poe_dbglog (ses,"PADO received: %P", p_in);
    }
    
    memcpy(&ses->remote, &p_in->addr, sizeof(struct sockaddr_ll));
    memcpy( &ses->curr_pkt.addr, &ses->remote , sizeof(struct sockaddr_ll));
    
    ses->curr_pkt.hdr->code = PADR_CODE;
    
    /* The HOST_UNIQ has been verified already... there's no "if" about this */
    /* if(ses->filt->htag) */
    copy_tag(&ses->curr_pkt,get_tag(p_in->hdr,PTT_HOST_UNIQ));  
    
    if (ses->filt->ntag) {
        ses->curr_pkt.tags[TAG_AC_NAME]=NULL;
    }
//    copy_tag(&ses->curr_pkt,get_tag(p_in->hdr,PTT_AC_NAME));
    
    if(ses->filt->stag) {
        ses->curr_pkt.tags[TAG_SRV_NAME]=NULL;
    }
    copy_tag(&ses->curr_pkt,get_tag(p_in->hdr,PTT_SRV_NAME));
    
    copy_tag(&ses->curr_pkt,get_tag(p_in->hdr,PTT_AC_COOKIE));
    copy_tag(&ses->curr_pkt,get_tag(p_in->hdr,PTT_RELAY_SID));
    
    ses->state = PADS_CODE;

    create_msg(BCM_PPPOE_CLIENT_STATE_PADS);
    syslog(LOG_CRIT,"PPP server detected.\n");

    ses->retransmits = 0;
    
    send_disc(ses, &ses->curr_pkt);
    (*p_out) = &ses->curr_pkt;
    
    if (ses->np)
        return 1;
    
    return 0;
}
示例#11
0
int connector_write(connector *cr, unsigned short cmd)
{
    unsigned char *msg;
    size_t sz;
    int ret = create_msg(cmd, &msg, &sz);
    if (ret != 0)
        return ret;
    ret = connector_write(cr, msg, sz);
    free(msg);
    return ret;
}
示例#12
0
int conn_write(conn *c, unsigned short cmd, uint64_t uid)
{
    unsigned char *msg;
    size_t sz;
    int ret = create_msg(cmd, uid, &msg, &sz);
    if (0 != ret)
        return ret;
    ret = conn_write(c, msg, sz);
    free(msg);
    return ret;
}
示例#13
0
文件: dhcp.c 项目: EtherGraf/ethersex
/*---------------------------------------------------------------------------*/
static void send_discover(void) {
  uint8_t *end;
  struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;
  
  create_msg(m);
  
  end = add_msg_type(&m->options[4], DHCPDISCOVER);
  end = add_req_options(end);
  end = add_end(end);
  
  uip_send(uip_appdata, end - (uint8_t *)uip_appdata);
}
示例#14
0
static void test_rqnt_cb(void)
{
	struct mgcp_config *cfg;
	struct msgb *inp, *msg;

	cfg = mgcp_config_alloc();
	cfg->rqnt_cb = rqnt_cb;

	cfg->trunk.number_endpoints = 64;
	mgcp_endpoints_allocate(&cfg->trunk);

	mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));

	inp = create_msg(CRCX);
	msgb_free(mgcp_handle_message(cfg, inp));
	msgb_free(inp);

	/* send the RQNT and check for the CB */
	inp = create_msg(RQNT);
	msg = mgcp_handle_message(cfg, inp);
	if (strncmp((const char *) msg->l2h, "200", 3) != 0) {
		printf("FAILED: message is not 200. '%s'\n", msg->l2h);
		abort();
	}

	if (cfg->data != (void *) '9') {
		printf("FAILED: callback not called: %p\n", cfg->data);
		abort();
	}

	msgb_free(msg);
	msgb_free(inp);

	inp = create_msg(DLCX);
	msgb_free(mgcp_handle_message(cfg, inp));
	msgb_free(inp);
	talloc_free(cfg);
}
示例#15
0
文件: dhcpc.c 项目: AriZuu/picoos-net
static void
send_discover(void)
{
  uint8_t *end;
  struct dhcp_msg *m = (struct dhcp_msg *)&dhcp_msg_buf;

  create_msg(m);

  end = add_msg_type(&m->options[4], DHCPDISCOVER);
  end = add_req_options(end);
  end = add_end(end);

  uosFileWrite(s.conn, (void*)m, end - (uint8_t*)m);
}
示例#16
0
static void send_request (void)
{
  u8_t *end;
  dhcpMsg_t *m = (dhcpMsg_t *) uip_appdata;

  create_msg (m);

  end = add_msg_type (&m->options [4], DHCPREQUEST);
  end = add_server_id (end);
  end = add_req_ipaddr (end);
  end = add_end (end);

  uip_send (uip_appdata, end - (u8_t *) uip_appdata);
}
示例#17
0
/*---------------------------------------------------------------------------*/
static void
send_request(void)
{
  uint8_t *end;
  struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;

  create_msg(m);
  
  end = add_msg_type(&m->options[4], DHCPREQUEST);
  end = add_server_id(end);
  end = add_req_ipaddr(end);
  end = add_end(end);
  
  uip_send(uip_appdata, (int)(end - (uint8_t *)uip_appdata));
}
示例#18
0
int
tac_create_author(struct tac_handle *h, int method, int type, int service)
{
	struct tac_author_request *areq;

	create_msg(h, TAC_AUTHOR, method, type);

	areq = &h->request.u.author_request;
	areq->authen_meth = method;
	areq->priv_lvl = TAC_PRIV_LVL_USER;
	areq->authen_type = type;
	areq->service = service;

	return 0;
}
示例#19
0
int
tac_create_authen(struct tac_handle *h, int action, int type, int service)
{
	struct tac_authen_start *as;

	create_msg(h, TAC_AUTHEN, action, type);

	as = &h->request.u.authen_start;
	as->action = action;
	as->priv_lvl = TAC_PRIV_LVL_USER;
	as->authen_type = type;
	as->service = service;

	return 0;
}
示例#20
0
文件: dhcpc.c 项目: AriZuu/picoos-net
/*---------------------------------------------------------------------------*/
static void
send_request(void)
{
  uint8_t *end;
  struct dhcp_msg *m = (struct dhcp_msg *)&dhcp_msg_buf;

  create_msg(m);
  
  end = add_msg_type(&m->options[4], DHCPREQUEST);
  end = add_server_id(end);
  end = add_req_ipaddr(end);
  end = add_end(end);
  
  uosFileWrite(s.conn, (void*)m, end - (uint8_t*)m);
}
示例#21
0
/*---------------------------------------------------------------------------*/
static void
send_request(void)
{
  u8_t *end;
  struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata;

  create_msg(m);
  
  end = add_msg_type(&m->options[4], DHCPREQUEST);
  end = add_server_id(end);
  end = add_req_ipaddr(end);
  end = add_req_host_name(end, HOSTNAME);
  end = add_end(end);
  
  uip_send(uip_appdata, end - (u8_t *)uip_appdata);
}
示例#22
0
/**************
 * Exec targets with recursive calls
 **************/
void exec_target_rec(DIME_MSG* response_msg, int socket, rule_t* rule, rule_node_t* list) {
	str_node_t* sptr;
	rule_node_t* rptr;
	for(sptr = rule->deps; sptr != NULL; sptr = sptr->next) {
		// for each dependency, see if there's a rule, then exec that rule
		for(rptr = list; rptr != NULL; rptr = rptr->next) {
			if(strcmp(sptr->str, rptr->rule->target) == 0) {
				exec_target_rec(response_msg, socket, rptr->rule, list);
			}
		}
	}
	
	str_node_t* s_ptr;
	for(s_ptr = rule->commandlines; s_ptr != NULL; s_ptr = s_ptr->next) {
		if(!create_msg(response_msg, EXECUTE_ACK, s_ptr->str, strlen(s_ptr->str))) { error("Server failed to create proper response"); }
		send_msg(response_msg, socket);
	}
}
示例#23
0
void watchdog_main_task()
{
    MVI_GENERIC_MSG_HEADER_T wd_msg;
    int msgid = create_msg(MVI_WD_MSGQ_KEY);
    if(msgid < 0)
    {
	logger_info("Failed to open WatchDog message");
	exit(0);
    }
    register_modules();

    while(1) {
    	recv_msg(msgid, (void *) &wd_msg, sizeof(MVI_GENERIC_MSG_HEADER_T), 5);
    	wd_msg_handler((MVI_GENERIC_MSG_HEADER_T *) &wd_msg);
    	usleep(10000);
    	wd_action();
    }
}
void Cli_Port_Manager:: thread_body(base_socket cli_sock){
	  cout<<"---------------------------------------------------------------------------"<<endl;
	  cout<<"---------------------------------------------------------------------------"<<endl;
	  cout<<"Thread Cli_Port_Manager started"<<endl;
	  cout<<"Thread id "<<this_thread::get_id()<<endl;
	  int ctrl;
	  string service_name;
	  string buff;
	  
	  ctrl=cli_sock.recv_msg(buff);
	  if (ctrl<0) 
	      cout<<"Cli_Port_Manager:: error receaving message"<<endl;
	  
	  service_name=buff;
	  cout<<service_name<<endl;
	  string signature="";
	  string ip="";
	  int port;
	  string msg;	
	  
	  if(list_manager->choose_sp(service_name, &ip,&port,&signature)==0){
	      
	      ctrl=create_msg(msg,"","|",ip,port,signature);
	      if (ctrl!=0)
		cout<<"Cli_Port_Manager:: error creating message for client"<<endl;
	  }
	  else{
	      msg="Error: No services named ";
	      msg+=service_name;
	      msg+=" available";
	  }
	  
	  ctrl=cli_sock.send_msg(msg);
	  if (ctrl<0) 
	      cout<<"Cli_Port_Manager:: error sending message"<<endl;
	  else{
	      cout<<"message ' "<<msg<<" ' sended"<<endl;
	  }
	  cli_sock.Close();
	  
	  cout<<endl<<"Fine thread SP_Port_Manager"<<endl;
	  
	  unlock_accept();
}
示例#25
0
文件: msg.c 项目: bdidemus/wine
/**************************************************************************
 *          WsCreateMessageForChannel		[webservices.@]
 */
HRESULT WINAPI WsCreateMessageForChannel( WS_CHANNEL *channel_handle, const WS_MESSAGE_PROPERTY *properties,
                                          ULONG count, WS_MESSAGE **handle, WS_ERROR *error )
{
    WS_ENVELOPE_VERSION version_env;
    WS_ADDRESSING_VERSION version_addr;
    HRESULT hr;

    TRACE( "%p %p %u %p %p\n", channel_handle, properties, count, handle, error );
    if (error) FIXME( "ignoring error parameter\n" );

    if (!channel_handle || !handle) return E_INVALIDARG;

    if ((hr = WsGetChannelProperty( channel_handle, WS_CHANNEL_PROPERTY_ENVELOPE_VERSION, &version_env,
                                    sizeof(version_env), NULL )) != S_OK || !version_env)
        version_env = WS_ENVELOPE_VERSION_SOAP_1_2;

    if ((hr = WsGetChannelProperty( channel_handle, WS_CHANNEL_PROPERTY_ADDRESSING_VERSION, &version_addr,
                                    sizeof(version_addr), NULL )) != S_OK || !version_addr)
        version_addr = WS_ADDRESSING_VERSION_1_0;

    return create_msg( version_env, version_addr, properties, count, handle );
}
示例#26
0
static int std_rcv_pads(struct session* ses,
                        struct pppoe_packet *p_in,
                        struct pppoe_packet **p_out){
    if( verify_packet(ses, p_in) < 0)
        return -1;
    
    if (DEB_DISC)
        poe_dbglog (ses,"Got connection: %x",
                    ntohs(p_in->hdr->sid));
    poe_info (ses,"Got connection: %x", ntohs(p_in->hdr->sid));
    
    ses->sp.sa_family = AF_PPPOX;
    ses->sp.sa_protocol = PX_PROTO_OE;
    ses->sp.sa_addr.pppoe.sid = p_in->hdr->sid;
    memcpy(ses->sp.sa_addr.pppoe.dev,ses->name, IFNAMSIZ);
    memcpy(ses->sp.sa_addr.pppoe.remote, p_in->addr.sll_addr, ETH_ALEN);
    
    create_msg(BCM_PPPOE_CLIENT_STATE_CONFIRMED);
    syslog(LOG_CRIT,"PPP session established.\n");

    return 1;
}
int main(int argc, char **argv){
  
  HEADER *hp;
  u_char *msg, *cp, *eom;
  int msglen;
  FILE *f;

  assert(argc==2);
  f = fopen (argv[1], "r");
  assert(f!=NULL);
  assert ((fscanf(f, "%d", &something)) != 0);
  

  msg = (u_char *) malloc(10000*sizeof(u_char));
  msglen = create_msg(msg, 10000);

  hp = (HEADER *) msg;

  /*
  printf("Enter value for something:");
  scanf("%d", &something);
  */

  cp = msg + sizeof(HEADER);
  eom = msg + msglen;

  printf("opcode = %d\n",hp->opcode);
  
  switch(hp->opcode){
  case ns_o_iquery:           /* ns_o_iquery = */ 
    req_iquery(hp, &cp, eom, &msglen, msg);
    break;
  default:
    printf("We only support inverse queries!\n");
  }

  return 0;

}
示例#28
0
/*********
 * Given a target list and the list of rules, execute the targets.
 *********/
int execute_targets(DIME_MSG* response_msg, int socket, char* targetv, rule_node_t* list) {
	rule_node_t* ptr = list;
	for(ptr = list; ptr != NULL; ptr = ptr->next) {
		if(strcmp(targetv, ptr->rule->target) == 0) {
			exec_target_rec(response_msg, socket, ptr->rule, list);
			break;
		}
	}
	if(ptr == NULL) {
		char message[504] = "Rule (";
		strcat(message, targetv);
		strcat(message, ") doesnt exist");
					
		if(!create_msg(response_msg, ERROR_MSG, message, strlen(message))) { error("Server failed to create proper response"); }

		
		send_msg(response_msg, socket);
		return 0;
	}
	
	return 1;
}
示例#29
0
void* serve_client(void* vars)
{
	DIME_MSG* server_msg = (DIME_MSG*)malloc(sizeof(DIME_MSG));
	DIME_MSG* client_msg  = (DIME_MSG*)malloc(sizeof(DIME_MSG));
	THREAD* t_vars = vars;	


	static int thread_id = 0;
	thread_id++;
	
	int new_socketfd = t_vars->socket;
	char* ip = inet_ntoa(t_vars->client_addr.sin_addr);
	int state = STATE_READY;
	
	while(true)
	{
		if(!read_msg(client_msg, new_socketfd)) { printf("Client %s disconnected\n", ip); break; }

		if(state == STATE_READY)
		{
			if(client_msg->msg_type == HANDSHAKE_MSG)
			{
				state = STATE_CONNECTED;
				if(!create_msg(server_msg, HANDSHAKE_ACK, NULL, 0)) { error("Server failed to create proper response"); } //dont know how else to handle this
				printf("Handshake received from %s\n", ip);
				send_msg(server_msg, new_socketfd);
			}
			else
			{
				//trying to concat msg->payload which is 504 bytes is bad idea
				char message[] = "Error: Awaiting handshake before accepting requests";
				if(!create_msg(server_msg, ERROR_MSG, message, strlen(message))) { error("Server failed to create proper response");  }
				printf("Error Msg (%s) sent to %s\n", message, ip);
				printf("Closing connection with %s\n", ip);
				send_msg(server_msg, new_socketfd);
				break;
			}
		}
		else if(state == STATE_CONNECTED)
		{

			if(client_msg->msg_type == EXECUTE_MSG)
			{
				printf("%s requested execution of (%s)\n", ip, client_msg->payload);			

				if(!execute_targets(server_msg, new_socketfd, client_msg->payload, list))
				{
					printf("Closing connection with %s\n", ip);		
					break; 
				}
				create_msg(server_msg, EXECUTE_END, NULL, 0);
				send_msg(server_msg, new_socketfd);
			}
			else
			{
			
				char* message = "Error: Server only accepting execution messages";
				if(!create_msg(server_msg, ERROR_MSG, message, strlen(message))) { error("Server failed to create proper response"); }
				send_msg(server_msg, new_socketfd);
				printf("Error Msg (%s) sent to %s\n", message, ip);
				printf("Closing connection with %s\n", ip);
				break;
			}
		}
		else { error("Server in unknown state"); }
	}

	close_socket(new_socketfd);
	free(server_msg);
	free(client_msg);
	free(vars);
	return;
}
示例#30
0
文件: ipcmk.c 项目: sebras/util-linux
int main(int argc, char **argv)
{
	int permission = 0644;
	int opt;
	size_t size = 0;
	int nsems = 0;
	int ask_shm = 0, ask_msg = 0, ask_sem = 0;
	static const struct option longopts[] = {
		{"shmem", required_argument, NULL, 'M'},
		{"semaphore", required_argument, NULL, 'S'},
		{"queue", no_argument, NULL, 'Q'},
		{"mode", required_argument, NULL, 'p'},
		{"version", no_argument, NULL, 'V'},
		{"help", no_argument, NULL, 'h'},
		{NULL, 0, NULL, 0}
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	while((opt = getopt_long(argc, argv, "hM:QS:p:Vh", longopts, NULL)) != -1) {
		switch(opt) {
		case 'M':
			size = strtosize_or_err(optarg, _("failed to parse size"));
			ask_shm = 1;
			break;
		case 'Q':
			ask_msg = 1;
			break;
		case 'S':
			nsems = strtos32_or_err(optarg, _("failed to parse elements"));
			ask_sem = 1;
			break;
		case 'p':
			permission = strtoul(optarg, NULL, 8);
			break;
		case 'h':
			usage(stdout);
			break;
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		default:
			errtryhelp(EXIT_FAILURE);
		}
	}

	if(!ask_shm && !ask_msg && !ask_sem)
		usage(stderr);

	if (ask_shm) {
		int shmid;
		if (-1 == (shmid = create_shm(size, permission)))
			err(EXIT_FAILURE, _("create share memory failed"));
		else
			printf(_("Shared memory id: %d\n"), shmid);
	}

	if (ask_msg) {
		int msgid;
		if (-1 == (msgid = create_msg(permission)))
			err(EXIT_FAILURE, _("create message queue failed"));
		else
			printf(_("Message queue id: %d\n"), msgid);
	}

	if (ask_sem) {
		int semid;
		if (-1 == (semid = create_sem(nsems, permission)))
			err(EXIT_FAILURE, _("create semaphore failed"));
		else
			printf(_("Semaphore id: %d\n"), semid);
	}

	return EXIT_SUCCESS;
}