从变量加载IP地址和PORT [英] Load IP address and PORT from a variable
本文介绍了从变量加载IP地址和PORT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决了...
Solved...
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
推荐答案
可能是我错了,但对我而言,看起来你正在释放之前的 / b>分配像IP_CS这样的变量。
当你不再需要时,你应该释放内存。
May be I'm wrong, but for me, it looks like you are freeing the memory before assigning the variables like IP_CS.
You should free the memory, when you don't need it anymore.
printf("\nNow printing each saved string:\n");
for (jj=0; jj<ii;> printf("String %d: %s\n", jj, allwords[jj]);
// freeing the memory:
free(allwords[jj]);
}
// trying to acces freed memory!?
char * IP_CS = allwords[0];
char *IP_HMI = allwords[2];
char *IP_OBCU = allwords[4];
char *IP_ASR = allwords[6];
char *IP_RSO = allwords[8];
char *IP_RSO_D = allwords[10];
int PORT_CS = atoi(allwords[12]);
int PORT_HMI = atoi(allwords[14]);
int PORT_OBCU = atoi(allwords[16]);
int PORT_ASR = atoi(allwords[18]);
int PORT_RSO = atoi(allwords[20]);
int PORT_RSO_D = atoi(allwords[22]);
BTW:我希望这只是一个简短的测试程序。否则,您应该使用LoadSettings(),SetUpSockets()等函数来构建代码。
BTW: I hope this is just a short test program. Otherwise you should structure your code a bit more with functions like LoadSettings(), SetUpSockets() etc.
根据代码,IP地址和端口似乎存储在名为configruation的文件中IP_CONFIG.txt。为了正确使用IP_CS和PORT_CS变量,您需要在配置文件中正确定义这些设置。
您可以通过在调试中单步执行代码来获得良好的理解模式并准确地看到程序内部将会是一个很好的学习经历。
As per the code it seems like IP address and port is stored in a configruation file named IP_CONFIG.txt. In order to correctly use IP_CS and PORT_CS variables you need to correctly define these settings in the configuration file.
You can get a good understanding by stepping into the code in debug mode and exactly see what is going inside the program which will be a great learning experience.
这篇关于从变量加载IP地址和PORT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文