示例#1
0
文件: main.go 项目: GeorgFleig/gretun
// register at server and create GRE tunnel
func register(tun *gretun.Tunnel) {
	log.Println("Requesting GRE IP from server ..")
	var greIp net.IP = nil
	statusCode, body := httpReq("http://" + serverIp + ":8080/reg")
	if statusCode != 0 {
		log.Printf("Response: %d (%s): %s\n", statusCode, http.StatusText(statusCode), body)
		greIp = net.ParseIP(string(body))
	}
	if greIp != nil {
		tun.CGreIp = greIp
		if tun.Create() {
			log.Println("GRE Tunnel created.")
		} else {
			log.Println("Failed creating GRE Tunnel.")
		}
	} else {
		log.Fatalln("Did not get a GRE IP address from server.")
	}
}