-2

I want to modify the dhcp4 source code to notify the ddns server to set the dynamic domain name when assigning the lease, but I added the nanomsg statement in dhcp4_srv.cc. When my nanomsg performs shutdown or close, the dhcp4 service will automatically close. This is why there is no other way to implement dynamic domain names (my dynamic domain name mainly sends the field set by the foreground and the mac address and IP address to the ddns server, or it may be the login account of the foreground). Someone can help me? thank you very much.

if (lease) {
// We have a lease! Let's set it in the packet and send it back to
// the client.
// 我们有租约! 让我们在数据包中进行设置,然后将其发送回客户端。
if (fake_allocation) {
//租约建议
LOG_INFO(lease4_logger, DHCP4_LEASE_ADVERT)
.arg(query->getLabel())
.arg(lease->addr_.toText());
} else {
//成功授予租约
LOG_INFO(lease4_logger, DHCP4_LEASE_ALLOC)
.arg(query->getLabel())
.arg(lease->addr_.toText())
.arg(lease->valid_lft_);

int rc = 0;
int pair_socket = 0;
int str_len = 0;
char buf[256] = { 0 };
char buf1[256] = { 0 };
int timeo = 5000;
//计算长度
str_len = strlen(HELLOWORLD);
//初始化socket
pair_socket = nn_socket(1, NN_PAIR);
if (pair_socket == -1) {
    printf("nn_socket failed! error: %s.\n", nn_err_strerror(errno));
    //system("pause");
    nn_err_abort();
    //return 0;
}
//设置超时
rc = nn_setsockopt(pair_socket, 0, NN_SNDTIMEO, &timeo, sizeof(timeo));
rc = nn_setsockopt(pair_socket, 0, NN_RCVTIMEO, &timeo, sizeof(timeo));
//连接服务端
rc = nn_connect(pair_socket, SOCKET_ADDRESS2);
if (rc < 0) {
    printf("bind failed! error: %s.\n", nn_err_strerror(errno));
    //system("pause");
    nn_err_abort();
    //return 0;
}
//将hello world复制到buf中
memcpy(buf, HELLOWORLD, str_len);

//发送数据
rc = nn_send(pair_socket, buf, str_len, 0);
if (rc < 0) {
    printf("nn_send failed! error: %s.rc = %d.\n", nn_err_strerror(errno), rc);
}
//打印
printf("send:%s\n", buf);
//这里主要是测试使用,平时项目不要使用标签
//接收数据
rc = nn_recv(pair_socket, buf1, 256, 0);
if (rc < 0) {
    printf("nn_recv failed! error: %s.rc = %d.\n", nn_err_strerror(errno), rc);

}
//打印
printf("recv:%s\n", buf1);
memset(buf1, 0, 256);
//Sleep(1000);

//关闭套接字
rc = nn_shutdown(pair_socket, 1);
if (rc != 1) {
    printf("nn_close failed! error: %s.\n", nn_err_strerror(errno));
    //system("pause");
    nn_err_abort();
    //return 0;
}
std::cout << "testtttttttttttttttttttttttttttttttttt "
          << "hostnameeeeeeeeeeeeeeeeeeeeeeeeeeeeee:" << lease->hostname_ << std::endl;
std::cout << "testtttttttttttttttttttttttttttttttttt "
          << "ipppppppppppppppppppppppppppppppppppp:" << lease->addr_.toText() << std::endl;

std::cout << "lease ALLOC  " << __LINE__ << "  file name  " << __FILE__
          << "  HOST:" << lease->hostname_ << std::endl;
std::cout << "lease ALLOC  " << __LINE__ << "  file name  " << __FILE__
          << "  IP:" << lease->addr_.toText() << std::endl;


}
bingogu
  • 1
  • 1
  • 1
    Welcome to Stack Overflow. Please take the [tour](https://stackoverflow.com/tour) and also read [How to Ask](https://stackoverflow.com/help/how-to-ask). Stack Overflow is not a free script writing service. Your own research and code attempts are expected. Please edit the question to include your code in a [Minimal, Complete, and Verifiable](https://stackoverflow.com/help/minimal-reproducible-example) example. It is also not clear what your question actually is, can you please provide more context on the specific issue you are having? – Brandon McClure Nov 21 '19 at 03:21
  • I don't mean to find someone to help write the code, I just want to see if anyone knows how to modify the source code of keadhcp, I want to know if there is any experience to share, I can not provide the specific code snippet, because they are keadhcp With the source code, I will paste some code. You see my problem. When I nn_shutdown, this server will die. I don't understand it, so I want to ask. – bingogu Nov 21 '19 at 06:11
  • This is a small part of the source code, I changed the place, I added this piece of nanomsg code in the source code. – bingogu Nov 21 '19 at 06:13
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page in the help section for help clarifying this question. – JHBonarius Nov 21 '19 at 06:14
  • Sorry, I don't know how to make clear my needs. I just want to ask if you know how to modify the source code of keadhcp. – bingogu Nov 21 '19 at 06:41

1 Answers1

0

It sounds like you need some general information on the KEA software developed by Internet Systems Consortium aka: https://kea.isc.org/ I would read through the Kea docs, mailing lists and the general development wiki to try to hone in on the specific issue you are having with your code. Once you are able explain the issue you are having with your code you can edit your question with your details, and there is a much better chance that you will get more meaningful answers from this site.

Brandon McClure
  • 1,329
  • 1
  • 11
  • 32
  • I have read all the documents of the official website, but the main reason is still not clear, because I am a beginner, some of the content is not preliminary, the examples are not detailed enough, so I don't understand – bingogu Nov 22 '19 at 00:21
  • I can relate, first off you need a clear end goal, which is missing from your question. SO is focused on specific programming questions, So better off to ask about specific C issues you are having. (There are alot of questions out there though, search first!) If you are not a beginner in C, and need KEA specific info, your 100% best bet is to subscribe to the mailing list/talk to developers working on that software. If you are novice with both, break the problem down into smaller domains and create simple applications that will demonstrate how to solve those individual problems. – Brandon McClure Nov 22 '19 at 15:46
  • Ok, thank you for your suggestion, I have made some progress, thank you very much. – bingogu Nov 25 '19 at 00:14