CN1274119C - Method for dynamic modifying one-board IP address and sub-net mask address - Google Patents
Method for dynamic modifying one-board IP address and sub-net mask address Download PDFInfo
- Publication number
- CN1274119C CN1274119C CNB021600627A CN02160062A CN1274119C CN 1274119 C CN1274119 C CN 1274119C CN B021600627 A CNB021600627 A CN B021600627A CN 02160062 A CN02160062 A CN 02160062A CN 1274119 C CN1274119 C CN 1274119C
- Authority
- CN
- China
- Prior art keywords
- address
- board
- socket
- subnet mask
- modification
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
Images
Landscapes
- Small-Scale Networks (AREA)
Abstract
本发明涉及一种动态修改单板IP地址及子网掩码地址的方法,为了将IP地址的修改由静态修改方式变为动态修改方式,利用Psos操作系统下支持Socket标准接口的PNA模块,通过调用ioctl函数,按以下步骤动态地修改单板IP地址及子网掩码地址:对系统结构进行定义;对已定义好的系统结构清零;获取Socket标识符;对系统结构进行赋值;调用ioctl函数修改单板的参数;关闭Socket。与静态修改IP地址的传统方式相比,动态修改IP地址最大的好处就在于它无需重新启动单板,能节约启动单板所花费的时间,延长单板的寿命,而且使得IP地址的修改实时性,也减少IP地址修改对其它模块的影响。
The invention relates to a method for dynamically modifying the IP address and subnet mask address of a single board. In order to change the modification of the IP address from a static modification method to a dynamic modification method, the PNA module supporting the Socket standard interface under the Psos operating system is used. Call the ioctl function to dynamically modify the IP address and subnet mask address of the board according to the following steps: define the system structure; clear the defined system structure; obtain the Socket identifier; assign the system structure; call ioctl The function modifies the parameters of the board; closes the Socket. Compared with the traditional method of statically modifying the IP address, the biggest advantage of dynamically modifying the IP address is that it does not need to restart the board, which can save the time spent on starting the board, prolong the life of the board, and make the modification of the IP address real-time It also reduces the impact of IP address modification on other modules.
Description
技术领域technical field
本发明涉及网络通信领域,更具体地说,涉及一种动态修改单板IP(网际协议)地址或子网掩码地址的方法。The invention relates to the field of network communication, and more specifically relates to a method for dynamically modifying the IP (Internet Protocol) address or subnet mask address of a single board.
背景技术Background technique
一般的程序对于IP地址与子网掩码地址的修改是将所要修改的值赋给程序的全局变量,然后重新运行程序。如果未重新运行程序,则当终端显示IP地址与子网掩码地址已修改时,实际上并未真正完成修改。最简单的现象就是在调试环境中还能继续调试,因为当与单板通信并调试时,主机的调试环境是与单板IP地址有联系的,如果单板IP地址改变,那么主机与单板的联系也应当断开,也就是不能再对单板进行操作了,如果在调试环境中还能继续调试,则说明单板IP地址并未改变。另外,使用Windows操作系统中自带的‘ping’命令对IP地址ping包检查,即可看出联系是否已中断。The modification of the IP address and subnet mask address by a general program is to assign the value to be modified to the global variable of the program, and then re-run the program. If the program is not re-run, when the terminal shows that the IP address and subnet mask address have been modified, the modification has not actually been completed. The simplest phenomenon is that you can continue to debug in the debugging environment, because when communicating with the board and debugging, the debugging environment of the host is related to the IP address of the board. If the IP address of the board changes, the connection between the host and the board The connection should also be disconnected, that is, the board can no longer be operated. If you can continue to debug in the debugging environment, it means that the IP address of the board has not changed. In addition, use the 'ping' command that comes with the Windows operating system to check the ping packet of the IP address, and you can see whether the connection has been interrupted.
可见,现有技术虽然修改了单板IP地址,但是需要重新启动才能使用该IP地址,所以这种IP地址的修改实际上是一种静态的修改,而使用者往往忘记了重新启动,导致IP地址其实并没有修改。另外,如果使用者需要多次修改IP地址,采用上述静态修改方式则每次都要重新启动,使得工作效率大大降低。It can be seen that although the IP address of the single board is modified in the prior art, the IP address needs to be restarted to use the IP address, so the modification of the IP address is actually a static modification, and the user often forgets to restart, resulting in the IP The address has not actually changed. In addition, if the user needs to modify the IP address multiple times, the above static modification method needs to be restarted every time, which greatly reduces the work efficiency.
发明内容Contents of the invention
本发明要解决的技术问题在于,针对现有技术的上述缺陷,提供一种动态修改单板IP地址及子网掩码地址的方法,将IP地址的修改由静态修改方式变为动态修改方式,使得无需重新启动就能修改单板的IP地址。The technical problem to be solved by the present invention is to provide a method for dynamically modifying the single board IP address and subnet mask address for the above-mentioned defects of the prior art, and change the modification of the IP address from a static modification method to a dynamic modification method, The IP address of the board can be modified without rebooting.
本发明解决其技术问题所采用的技术方案是:一种动态修改单板IP地址及子网掩码地址的方法,其中,利用嵌入式操作系统中支持Socket标准接口的网络通讯模块,通过调用ioctl函数,按以下步骤动态地修改单板IP地址或子网掩码地址:对系统结构进行定义;对已定义好的系统结构清零;获取Socket标识符;对系统结构进行赋值;调用ioctl函数修改单板的IP地址或子网掩码地址;关闭Socket。The technical solution adopted by the present invention to solve its technical problems is: a method for dynamically modifying the single-board IP address and subnet mask address, wherein, utilizing the network communication module supporting the Socket standard interface in the embedded operating system, by calling ioctl function to dynamically modify the IP address or subnet mask address of the board according to the following steps: define the system structure; clear the defined system structure; obtain the Socket identifier; assign a value to the system structure; call the ioctl function to modify The IP address or subnet mask address of the board; close the Socket.
在本发明所述的方法中,所述嵌入式操作系统可以是Psos(实时操作系统),所述网络通讯模块为Psos操作系统中的PNA(Psos网络部件)模块。In the method of the present invention, the embedded operating system may be Psos (real-time operating system), and the network communication module is a PNA (Psos network component) module in the Psos operating system.
在本发明所述的方法中,所述ioctl函数带有三个参数,所述参数是所述Socket标识符、操作参数和所述系统接口结构的指针。In the method of the present invention, the ioctl function has three parameters, the parameters are the Socket identifier, the operation parameters and the pointer of the system interface structure.
在本发明所述的方法中,所述操作参数为‘SIOCSIFADDR’或‘SIOCSIFNETMASK’;如果操作参数是‘SIOCSIFADDR’,则修改所述单板IP地址;如果操作参数是‘SIOCSIFNETMASK’,则修改所述单板子网掩码地址。In the method of the present invention, the operating parameter is 'SIOCSIFADDR' or 'SIOCSIFNETMASK'; if the operating parameter is 'SIOCSIFADDR', modify the single board IP address; if the operating parameter is 'SIOCSIFNETMASK', modify the The subnet mask address of the above board.
与静态修改IP地址的传统方式相比,动态修改IP地址最大的好处就在于它无需重新启动单板,能节约启动单板所花费的时间,延长单板的寿命,而且使得IP地址的修改实时性,也减少IP地址修改对其它模块的影响。Compared with the traditional method of statically modifying the IP address, the biggest advantage of dynamically modifying the IP address is that it does not need to restart the board, which can save the time spent on starting the board, prolong the life of the board, and make the modification of the IP address real-time It also reduces the impact of IP address modification on other modules.
附图说明Description of drawings
下面将结合附图及实施例对本发明作进一步说明,附图中:The present invention will be further described below in conjunction with accompanying drawing and embodiment, in the accompanying drawing:
图1是本发明方法的流程图。Figure 1 is a flow chart of the method of the present invention.
具体实施方式Detailed ways
为了实现上述方案,本发明中可采用Psos操作系统,这是一种嵌入式操作系统,不同于普通操作系统,它已经被嵌入到单板中,软件运行是基于该系统;嵌入式操作系统在电子自动控制、电路设计、可以说只要是内嵌有高速CPU的机器(一般是一块电路板)都有使用,比如PDA。Psos操作系统按照功能结构分成六个主要模块,每个模块只针对它所对应的处理领域,比如专门计算的计算单元,专门用于调试的调试单元,其中的PNA模块是Psos操作系统中专门用于网络通讯的单元,包含所有Psos中支持网络通讯的组件。关于Psos系统结构,就是系统为了运行而与服务软件结合的一些结构体,可以理解为Psos系统的一部分,类似于Windows系统中使用的系统文件,正确地修改该文件可对系统进行优化配置。In order to realize above-mentioned scheme, can adopt Psos operating system among the present invention, this is a kind of embedded operating system, is different from ordinary operating system, and it has been embedded in the single board, and software operation is based on this system; Embedded operating system is in Electronic automatic control, circuit design, it can be said that as long as the machine (usually a circuit board) embedded with a high-speed CPU is used, such as a PDA. The Psos operating system is divided into six main modules according to the functional structure, and each module is only aimed at its corresponding processing field, such as a computing unit for special calculation, and a debugging unit for debugging. The PNA module is specially used in the Psos operating system. A unit for network communication, including all components in Psos that support network communication. Regarding the Psos system structure, it refers to some structures combined with the service software for the system to run. It can be understood as a part of the Psos system, similar to the system files used in the Windows system. Correctly modifying this file can optimize the configuration of the system.
要动态地修改IP地址与子网掩码地址,需要直接对硬件接口进行操作,本发明中采用ioctl函数来实现对IP地址与子网掩码地址的动态修改,ioctl是Socket接口中的一个输入、输出操作的函数,它是一个非常强大的函数。同时,本发明中采用Psos操作系统的PNA模块(也就是TCP/IP协议模块)来支持Socket接口标准,也就是支持该ioctl函数。关于Socket接口标准,Socket的原义是插口、接口的意思,简单地理解就是底层与上层的一个中间层,底层软件和上层软件在软件开发时都按照统一的标准来编写各自的代码,这样两个软件合并时,就无需再调试了。本发明中所写的就是上层部分,底层软件已经由Psos操作系统的制作者按照Socket的统一标准完成了。但是在使用它的接口时,需要区分使用的是Socket标准的函数,同时也可能出现多个Socket,为了区分不同的情况,就要使用Socket标识,它通过标准的Socket函数(就是socket同名函数)获取,获取后在每次调用Socket函数就必须带上这个标识作为参数,系统就会知道是在对某一个Socket进行操作,而不是对别的Socket进行操作。To modify IP address and subnet mask address dynamically, it is necessary to directly operate the hardware interface. In the present invention, the ioctl function is used to realize the dynamic modification of IP address and subnet mask address, and ioctl is an input in the Socket interface , the function of the output operation, it is a very powerful function. At the same time, the PNA module (that is, the TCP/IP protocol module) of the Psos operating system is used in the present invention to support the Socket interface standard, that is, to support the ioctl function. Regarding the Socket interface standard, the original meaning of Socket is the meaning of socket and interface. Simply understood, it is an intermediate layer between the bottom layer and the upper layer. When the software is merged, there is no need to debug any more. What is written in the present invention is exactly the upper layer part, and the bottom layer software has been completed according to the unified standard of Socket by the producer of Psos operating system. However, when using its interface, it is necessary to distinguish the functions of the Socket standard. At the same time, there may be multiple Sockets. In order to distinguish different situations, the Socket identifier must be used. It uses the standard Socket function (that is, the function of the same name as the socket) Acquisition, after acquisition, you must bring this identifier as a parameter every time you call the Socket function, and the system will know that it is operating on a certain Socket, not on other Sockets.
要实现本发明的方法,需要利用Psos操作系统的一些的系统结构和底层通用的Socket接口功能。To realize the method of the present invention, it is necessary to utilize some system structures and bottom general Socket interface functions of the Psos operating system.
本发明方法的流程如图1所示,其过程包括:The flow process of the inventive method is as shown in Figure 1, and its process comprises:
(1)对系统结构进行定义,本发明中使用嵌入式操作系统作为单板的操作系统,操作系统实际是一个软件运行的平台,它有多个模块各自支持不同的功能,必然会有支持网络的部分或模块,网络支持和运行的方式是可以被用户修改的,系统结构就是用户修改的一个平台,本发明通过修改该平台的参数来达到修改网络的目的;(1) system structure is defined, use embedded operating system as the operating system of single board among the present invention, and operating system is actually the platform that a software runs, and it has a plurality of modules to support different functions separately, must have supporting network The part or module, the mode of network support and operation can be modified by the user, the system structure is a platform modified by the user, and the present invention achieves the purpose of modifying the network by modifying the parameters of the platform;
(2)对已定义好的系统结构清零,也就是初始化系统结构,避免受到其它影响;(2) Clear the defined system structure, that is, initialize the system structure to avoid other influences;
(3)获取Socket标识符;(3) Obtain the Socket identifier;
(4)对系统结构进行赋值,也就是修改相应的系统结构,修改嵌入式操作系统网络结构的属性;(4) assign a value to the system structure, that is, modify the corresponding system structure, and modify the attributes of the network structure of the embedded operating system;
(5)调用ioctl函数修改单板的参数;(5) Call the ioctl function to modify the parameters of the single board;
(6)然后关闭Socket,完成一次修改动作。(6) Then close the Socket and complete a modification action.
本方法的关键部分在‘调用ioctl函数修改单板的参数’,注意在此之前接口的系统结构一定要有相应的赋值,否则是不会成功的。然后调用ioctl函数即可修改单板的参数,ioctl函数所带的三个参数依次是Socket标识符、操作参数和系统接口结构的指针。如果操作参数是‘SIOCSIFADDR‘,则整个函数调用的功能就是直接修改IP地址;如果操作参数是‘SIOCSIFNETMASK’,则整个函数调用的功能就是直接修改子网掩码地址。The key part of this method is 'calling the ioctl function to modify the parameters of the board'. Note that the system structure of the interface must have a corresponding assignment before this, otherwise it will not succeed. Then call the ioctl function to modify the parameters of the single board. The three parameters carried by the ioctl function are the Socket identifier, the operation parameter and the pointer of the system interface structure in turn. If the operation parameter is 'SIOCSIFADDR', the function of the entire function call is to directly modify the IP address; if the operation parameter is 'SIOCSIFNETMASK', the function of the entire function call is to directly modify the subnet mask address.
Psos系统在使用系统接口结构时不会发现它需要的参数被改变了,通讯时就会按照新的参数来建立TCP/IP连接,这样就等于动态修改了IP地址和子网掩码地址。When using the system interface structure, the Psos system will not find that the parameters it needs have been changed, and will establish a TCP/IP connection according to the new parameters during communication, which is equivalent to dynamically modifying the IP address and subnet mask address.
需要注意的是,调试工具是以IP地址来认识单板,所以IP地址修改之后,调试工具将认为相应的单板不存在了,所以调试工具会失去连接。但该单板在与外面建立连接时就会使用新的IP地址。通常的静态修改的处理方法则不然,系统接口并没有被修改,所以单板还是认为自己是原来的IP地址,只有等到单板重新启动时,重新写系统接口参数时才会修改。It should be noted that the debugging tool uses the IP address to recognize the board, so after the IP address is changed, the debugging tool will think that the corresponding board does not exist, so the debugging tool will lose the connection. But the single board will use a new IP address when establishing a connection with the outside world. The usual static modification method is not the same. The system interface has not been modified, so the board still thinks that it is the original IP address, and it will only be modified when the system interface parameters are rewritten when the board is restarted.
本发明中,针对IP地址的修改使用的是SIOCSIFADDR命令字,针对子网掩码地址的修改使用的是SIOCSIFNETMASK命令字。通过调用ioctl系统函数直接对端口进行操作,当主程序中调用该函数时,函数的输入参数BoardIP地址、BoardSubIP地址的值将直接修改IP地址值与子网掩码地址值。与静态修改IP地址的传统方式相比,动态修改IP地址最大的好处就在于它无需重新启动单板,能节约启动单板所花费的时间,延长单板的寿命,而且使得IP地址的修改实时性,也减少IP地址修改对其它模块的影响。In the present invention, the SIOCSIFADDR command word is used to modify the IP address, and the SIOCSIFNETMASK command word is used to modify the subnet mask address. The port is directly operated by calling the ioctl system function. When the function is called in the main program, the values of the input parameters BoardIP address and BoardSubIP address of the function will directly modify the IP address value and the subnet mask address value. Compared with the traditional method of statically modifying the IP address, the biggest advantage of dynamically modifying the IP address is that it does not need to restart the board, which can save the time spent on starting the board, prolong the life of the board, and make the modification of the IP address real-time It also reduces the impact of IP address modification on other modules.
Claims (4)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CNB021600627A CN1274119C (en) | 2002-12-26 | 2002-12-26 | Method for dynamic modifying one-board IP address and sub-net mask address |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CNB021600627A CN1274119C (en) | 2002-12-26 | 2002-12-26 | Method for dynamic modifying one-board IP address and sub-net mask address |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN1510877A CN1510877A (en) | 2004-07-07 |
| CN1274119C true CN1274119C (en) | 2006-09-06 |
Family
ID=34237743
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CNB021600627A Expired - Fee Related CN1274119C (en) | 2002-12-26 | 2002-12-26 | Method for dynamic modifying one-board IP address and sub-net mask address |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN1274119C (en) |
Families Citing this family (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US7738484B2 (en) * | 2004-12-13 | 2010-06-15 | Intel Corporation | Method, system, and apparatus for system level initialization |
| US8412207B2 (en) | 2006-12-21 | 2013-04-02 | Core Wireless Licensing S.A.R.L. | Method of providing a mobility service |
| CN107832096A (en) * | 2017-09-29 | 2018-03-23 | 五八有限公司 | URL collocation method and terminal |
| CN114697293B (en) * | 2022-03-30 | 2023-11-10 | 西安北方华创微电子装备有限公司 | Data transmission method, lower computer and controller |
-
2002
- 2002-12-26 CN CNB021600627A patent/CN1274119C/en not_active Expired - Fee Related
Also Published As
| Publication number | Publication date |
|---|---|
| CN1510877A (en) | 2004-07-07 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN102014044A (en) | Network domain conflict avoiding method and router using same | |
| CN1274119C (en) | Method for dynamic modifying one-board IP address and sub-net mask address | |
| CN116610455A (en) | Resource constraint description system and method of programmable network element equipment | |
| CN107329792A (en) | A kind of Docker containers start method and device | |
| CN103188098A (en) | Method, system and device for disaster recovery switching | |
| CN111314567B (en) | Communication method based on cascade connection of multiple IAD (inter-integrated access device) devices | |
| CN114969207B (en) | A database reading and writing method and system | |
| CN1512379A (en) | Method for automatic configuration or restoring of computer system network configuration | |
| CN107995326A (en) | The management method and device of a kind of capacitor network | |
| CN112099902A (en) | Network adapter configuration method, device, electronic device and storage medium for virtual machine | |
| CN1904842A (en) | Apparatus and method of CMOS parameter setting and maintaining | |
| CN1399209A (en) | Parallel distributed-data base processing method and device | |
| CN116150250B (en) | PostgreSQL-based dual-port analysis method and device | |
| CN100341257C (en) | ASC realizing method in switching single board load | |
| CN1744047A (en) | Method for realizing dynamic layout of high-performance server based on group structure | |
| CN1956392A (en) | Method, device and system for realizing multi-service board architecture | |
| CN1176423C (en) | Mainboard test program processing system and method | |
| CN113064702B (en) | Method and device for accelerating configuration of SPD information by deploying memory module | |
| CN1889462A (en) | Method and system for realizing network management and network element configuration operation | |
| CN1300983C (en) | Exchange dynamic configuration restoring method | |
| CN1858705A (en) | Method for realizing network processor dynamic loading micro code and network device | |
| CN101063941A (en) | Automated full remote control method | |
| CN114968476B (en) | Method and terminal for realizing remote mirror image editing function of cloud computer scheme | |
| CN117560235B (en) | A method and device for automatic network access | |
| CN100344114C (en) | Access method and realizing method for network apparatus |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| C14 | Grant of patent or utility model | ||
| GR01 | Patent grant | ||
| CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20060906 Termination date: 20141226 |
|
| EXPY | Termination of patent right or utility model |