how to change client source port every connect in FRDMK64

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

how to change client source port every connect in FRDMK64

740件の閲覧回数
sudhakarp
Contributor V

Hi,

i am using KDS3.0 and KSDK1.3.0 example. i am using FRDMk64 board and ethernet_to_serial example.in my application code my device act as Client so i will connect to server. its working fine. but every disconnect and connect my source port should change for that what i want to do..? where i can see source port assignment ..? actually i want to increase the source port number for every connection.how to do that..?

NOTE: i want to change device PORT number not server PORT number.

regards,

sudhakar p

ラベル(1)
0 件の賞賛
返信
1 返信

490件の閲覧回数
Carlos_Musich
NXP Employee
NXP Employee

Hi

if you are using TCP sockets you must have a structure of type sockaddr_in. In field sin_port you may indicate the destination port. Refer to the snippet below.

#define DESTPORT 1030

    sockaddr_in    addr;

    addr.sin_family      = AF_INET;

    addr.sin_port        = 0;

    addr.sin_addr.s_addr = INADDR_ANY;

        error = bind(sock, &addr, sizeof(addr));

    addr.sin_port        = DESTPORT;

    addr.sin_addr.s_addr = IPADDR(192,168,1,132); //Server address

     error = connect(sock, &addr, sizeof(addr));

Regards,

Carlos

0 件の賞賛
返信