NSIs checks whether the port is occupied

Source: Internet
Author: User

! IncludeLogiclib. nsh

! DefineAf_inet2
! DefineSock_stream1
! DefineIpproto_tcp6

Section
; Initialize Winsock
System: alloc400
Pop$0
System: Call ws2_32: wsastartup(I514, ir0) I. r1
Strcmp$10 0Done

; Create a socket for listening for incoming connection requests
System: Call ws2_32: Socket (I $ {Af_inet} , I $ {Sock_stream} , I $ {Ipproto_tcp} ) I. r1
Strcmp $1 0 Cleanup
System: Call ws2_32: inet_addr (T "127.0.0.1" ) I. S
System: Call ws2_32: htons (I80) I. s
System: Call "* (& I2 $ {Af_inet} , & I2 S, I s, & T8) I. R2"
; Bind the socket.
System: Call ws2_32: bind (Ir1, ir2, I16) I. r3
$ {If} $3 =- 1
MessageBox Mb_iconinformation | Mb_ OK "BIND () failed ."
System: Call ws2_32: wsagetlasterror () I. r3
$ {If} $3 = 10048
MessageBox Mb_iconinformation | Mb_ OK "Port 80 is in use"
$ {Endif}
$ {Endif}
System: Call ws2_32: closesocket (Ir1)
System: free $2
Cleanup:
System: Call ws2_32: wsacleanup ()
Done:
System: free $0
Sectionend

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.